{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c5677129",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'b']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [\"a\",\"b\",\"c\",\"d\",\"e\"]\n",
    "a [0:2]# 获取0-2中间的元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5a91913c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'b']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [\"a\",\"b\",\"c\",\"d\",\"e\"]\n",
    "a[:2]# 从0 开始切，可省略0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f4fd55bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['b', 'c', 'd', 'e']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [\"a\",\"b\",\"c\",\"d\",\"e\"]\n",
    "a[1:]# 同样的，切到最后一个也可以省略最后的元素索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "272d730b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "b\n",
      "e\n",
      "d\n"
     ]
    }
   ],
   "source": [
    "#列表的索引list[index]\n",
    "list=[\"a\",\"b\",\"c\",\"d\",\"e\"]\n",
    "print(list[0])\n",
    "print(list[1])\n",
    "print(list[-1])\n",
    "print(list[-2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5cf171d2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[23, 25, 27]\n",
      "29\n",
      "[23, 27, 31]\n",
      "31\n",
      "[27, 29, 31, 33]\n"
     ]
    }
   ],
   "source": [
    "#切片\n",
    "#列表切片是指获取列表的一部分元素，通过指定索引的起始位置、结束位置或步长来对列表进行切片，切片出来的结果仍是一个列表类型。\n",
    "\n",
    "#语法：list[start,end,step]\n",
    "list=[23,25,27,29,31,33,35]\n",
    "print(list[0:3])\n",
    "print(list[3])\n",
    "print(list[0:6:2])\n",
    "print(list[-3])\n",
    "print(list[-5:-1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0492c3bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[23, 25, 27, 29, 31, 33, 35, 23, 25, 27, 29, 31, 33, 35, 23, 25, 27, 29, 31, 33, 35]\n"
     ]
    }
   ],
   "source": [
    "#重复\n",
    "list=[23,25,27,29,31,33,35]\n",
    "print(list * 3)#重复三次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "785ce2a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "#查找成员：\n",
    "#使用in可以检查列表中是否存在某个元素，如存在返回True，否则返回False。\n",
    "\n",
    "list1=[23,34,['hello world'],[31,35]]\n",
    "list2=['数据分析']\n",
    "list3=list1+list2#列表连接\n",
    "print('数据分析' in list3)# 查找成员\n",
    "print(['hello world'] in list3)#查找成员\n",
    "print(23 in list1)#查找成员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "8b72c441",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, ['hi friend'], [23, 45]]\n"
     ]
    }
   ],
   "source": [
    "#嵌套：列表嵌套是指在一个列表中，有元素的数据类型也是列表类型。\n",
    "list=[1,2,3,['hi friend'],[23,45]]\n",
    "print(list)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "30024600",
   "metadata": {},
   "outputs": [],
   "source": [
    "#查看列表的操作方法：使用print(dir(list))可以查看列表的索引方法和函数，如图所示，列表主要有append、clear、copy、count、extend、index、insert、pop、remove、reverse、sort等方法。\n",
    "\n",
    "#https://blog.csdn.net/weixin_39953102/article/details/113535829?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-4.no_search_link&spm=1001.2101.3001.4242.3\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f0564363",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# 课本项目练习P60\n",
    "# 列表是一个有序的对象集合\n",
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "40ddb4c9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7cd19030",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
